package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import managers.AffichageManager;
import beans.Commande;
import beans.User;

/**
 * Servlet implementation class PaiementServlet
 */
public class PaiementServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PaiementServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if ((User) request.getSession().getAttribute("user") == null)
		{
			request.setAttribute("error", "NO_USER_CONNECTED");
			request.getRequestDispatcher("/error").forward(request, response);
		}
		else
		{
			request.getSession().setAttribute("testnumerocarte", false);
			request.getSession().setAttribute("testcryptogramme", false);
			request.getSession().setAttribute("testdateexpiration", false);
			request.setAttribute("affichage", AffichageManager
					.buildAffichagePaiement((User) request.getSession().getAttribute(
							"user"), (Commande) request.getSession().getAttribute("panier")));
			request.getRequestDispatcher("/paiement.jsp").forward(request, response);
		}
	}

}
